import { createRouter, createWebHistory } from "vue-router";

// 自动引入modules下的所有文件 eager表示懒加载是否开启
const modulesFiles = import.meta.glob("./modules/*.js", { eager: true });
const routes = [];
// 遍历modulesFiles
Object.keys(modulesFiles).forEach((key) => {
  const moduleFile = modulesFiles[key];
  const route = moduleFile.default;
  routes.push(...route);
});

// 创建路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      meta: { title: "" },
      redirect: "/home",
    },
    ...routes,
  ],
});
export default router;
